/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rhythm.commons.datetime;

import com.rhythm.base.LateImmutableObject;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

/**
 *
 * @author Michael J. Lee
 */
public abstract class ImmutableCalendar extends GregorianCalendar implements LateImmutableObject{

    private static final long serialVersionUID = 1;
    private final boolean sealed;

    protected ImmutableCalendar(long timeInMills, TimeZone timeZone) {
        super();
        setTimeZone(timeZone);
        setTimeInMillis(timeInMills);
        sealed = true;
    }

    @Override
    public void roll(int field, boolean up) {
        throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
    }

    @Override
    public void roll(int field, int amount) {
        throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
    }

    @Override
    public void set(int field, int value) {

        if (sealed) {
            throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
        } else {
            super.set(field, value);
        }
    }

    @Override
    public void add(int field, int amount) {
        throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
    }

    public void setAreFieldsSet(boolean areFieldsSet) {
        throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
    }

    public void setTime(long time) {
        throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
    }

    @Override
    public void setTimeInMillis(long millis) {
        if (sealed) {
            throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
        } else {
            super.setTimeInMillis(millis);
        }
    }

    public void setIsSet(boolean[] isSet) {
        throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
    }

    public void setFields(int[] fields) {
        throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
    }

    @Override
    public void setFirstDayOfWeek(int value) {
        throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
    }

    @Override
    public void setGregorianChange(Date date) {
        throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
    }

    public void setIsTimeSet(boolean isTimeSet) {
        throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
    }

    @Override
    public void setLenient(boolean lenient) {
        throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
    }

    @Override
    public void setMinimalDaysInFirstWeek(int value) {
        throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
    }

    @Override
    public void setTimeZone(TimeZone zone) {
        if (sealed) {
            throw new UnsupportedOperationException("Cannot change any calendar values beause the object is immutable.");
        }
        super.setTimeZone(zone);
    }
}
